﻿@using Radzen.Blazor.Rendering
@using System.Linq
@using System.Collections
@using Radzen
@using Microsoft.AspNetCore.Components.Forms
@typeparam TValue
@inherits FormComponent<TValue>

@if (Items != null)
{
    <CascadingValue Value=this>
        @Items
    </CascadingValue>
}
@if (Visible)
{
    <div @ref="@Element" style="@Style" @attributes="Attributes" class="@GetCssClass()" id="@GetId()">
        @foreach (var item in allItems.Where(i => i.Visible))
        {
            <div @ref="@item.Element" id="@item.GetItemId()" @onclick="@(args => SelectItem(item))" @attributes="item.Attributes" class="@item.GetItemCssClass()" style="@item.Style">
                <div class="rz-radiobutton" @onkeypress="@(async args => { if (args.Code == "Space") { await SelectItem(item); } })" tabindex="@(Disabled || item.Disabled ? "-1" : $"{TabIndex}")">
                    <div class="rz-helper-hidden-accessible">
                        <input type="radio" disabled="@Disabled" name="@Name" value="@item.Value" tabindex="-1">
                    </div>
                    <div class=@ItemClassList(item)>
                        <span class=@IconClassList(item)></span>
                    </div>
                </div>
                @if (item.Template != null)
                {
                    <div class="rz-radiobutton-template">
                        @item.Template(item)
                    </div>
                } 
                else 
                {
                    <label class="rz-radiobutton-label">@((MarkupString)item.Text)</label>
                }
            </div>
        }
    </div>
}
